package com.sgb.kjwl.view.ui.activity.pick;

import android.content.Context;
import android.content.Intent;
import androidx.databinding.DataBindingUtil;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.view.inputmethod.InputMethodManager;
import android.widget.RadioGroup;

import com.bigkoo.pickerview.builder.OptionsPickerBuilder;
import com.bigkoo.pickerview.view.OptionsPickerView;
import com.sgb.kjwl.AppActivity;
import com.sgb.kjwl.R;
import com.sgb.kjwl.databinding.ActivityQuoteImmediatelyBinding;
import com.sgb.kjwl.di.pick.DaggerPickComponent;
import com.sgb.kjwl.di.pick.PickModule;
import com.sgb.kjwl.model.entity.BidEntity;
import com.sgb.kjwl.model.entity.InquiryCenterEntity;
import com.sgb.kjwl.model.entity.MachinePriceUnitEntity;
import com.sgb.kjwl.model.entity.OfferDeviceEntity;
import com.sgb.kjwl.model.entity.OfferLabourEntity;
import com.sgb.kjwl.model.entity.OfferMaterialEntity;
import com.sgb.kjwl.model.entity.PickDeviceEntity2;
import com.sgb.kjwl.model.entity.PickLabourEntity;
import com.sgb.kjwl.model.entity.PickPackersEntity;
import com.sgb.kjwl.model.entity.RateEntity;
import com.sgb.kjwl.model.entity.SuccessEntity;
import com.sgb.kjwl.model.entity.user.PickMaterialClassEntity;
import com.sgb.kjwl.view.ui.activity.self.authentication.CommitSuccessActivity;
import com.sgb.kjwl.viewmodel.pick.QuoteImmediatelyModel;
import com.swgk.core.base.di.AppComponent;
import com.swgk.core.util.MToast;

import java.io.Serializable;
import java.util.List;

import javax.inject.Inject;

import static com.sgb.kjwl.view.event.SuccessType.PICK_OFFER;

public class QuoteImmediatelyActivity extends AppActivity {
    private ActivityQuoteImmediatelyBinding binding;
    private InquiryCenterEntity inquiryCenterEntity;
    private PickPackersEntity pickPackersEntity;
    private PickDeviceEntity2 pickPackersEntity2;
    private PickMaterialClassEntity pickMaterialClassEntity;
    private PickLabourEntity pickLabourEntity;

    private BidEntity bidEntity;
    private int id;
    private List<RateEntity> rateEntityList;
    private List<MachinePriceUnitEntity> machinePriceUnitEntities;
    private OfferMaterialEntity offerMaterialEntity;
    private OfferLabourEntity offerLabourEntity;
    private OfferDeviceEntity offerDeviceEntity;
    private int ratePosition;
    private int unitPosition;
    private String rateId;
    private String no;
    @Inject
    QuoteImmediatelyModel model;

    public static void start(Context context) {
        start(context, null, 0);
    }

    public static void start(Context context, InquiryCenterEntity inquiryCenterEntity, int id) {
        Intent intent = new Intent();
        Bundle bundle = new Bundle();
        intent.setClass(context, QuoteImmediatelyActivity.class);
        intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
        bundle.putSerializable("inquiryCenterEntity", inquiryCenterEntity);
        bundle.putInt("id", id);
        intent.putExtras(bundle);
        context.startActivity(intent);
    }

    public static void startActivity(Context context, PickPackersEntity pickPackersEntity, int id) {
        Intent intent = new Intent();
        Bundle bundle = new Bundle();
        intent.setClass(context, QuoteImmediatelyActivity.class);
        intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
        bundle.putSerializable("pickPackersEntity", pickPackersEntity);
        bundle.putInt("id", id);
        intent.putExtras(bundle);
        context.startActivity(intent);
    }

    public static void startDevice(Context context, PickDeviceEntity2 pickPackersEntity2, int id) {
        Intent intent = new Intent();
        Bundle bundle = new Bundle();
        intent.setClass(context, QuoteImmediatelyActivity.class);
        intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
        bundle.putSerializable("pickPackersEntity2", pickPackersEntity2);
        bundle.putInt("id", id);
        intent.putExtras(bundle);
        context.startActivity(intent);
    }

    public static void startMateria(Context context, PickMaterialClassEntity pickMaterialClassEntity, int id) {
        Intent intent = new Intent();
        Bundle bundle = new Bundle();
        intent.setClass(context, QuoteImmediatelyActivity.class);
        intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
        bundle.putSerializable("pickMaterialClassEntity", pickMaterialClassEntity);
        bundle.putInt("id", id);
        intent.putExtras(bundle);
        context.startActivity(intent);
    }

    public static void startLabour(Context context, PickLabourEntity pickLabourEntity, int id) {
        Intent intent = new Intent();
        Bundle bundle = new Bundle();
        intent.setClass(context, QuoteImmediatelyActivity.class);
        intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
        bundle.putSerializable("pickLabourEntity", pickLabourEntity);
        bundle.putInt("id", id);
        intent.putExtras(bundle);
        context.startActivity(intent);
    }

    public static void startAgain(Context context, Object object, int id) {
        Intent intent = new Intent();
        Bundle bundle = new Bundle();
        intent.setClass(context, QuoteImmediatelyActivity.class);
        intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
        bundle.putSerializable("object", (Serializable) object);
        bundle.putInt("id", id);
        intent.putExtras(bundle);
        context.startActivity(intent);
    }

    @Override
    protected void setupActivityComponent(AppComponent appComponent) {
        DaggerPickComponent.builder()
                .appComponent(appComponent)
                .pickModule(new PickModule(this))
                .build()
                .inject(this);
    }

    @Override
    protected boolean statusBarDark() {
        return true;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    }

    @Override
    protected void initView() {
        binding = DataBindingUtil.setContentView(QuoteImmediatelyActivity.this, R.layout.activity_quote_immediately);
        binding.setViewModel(model.quoteImmediatelyEntity.get());
        binding.backView.setOnClickListener(this);
        binding.rlTaxRate.setOnClickListener(this);
        binding.tvCommit.setOnClickListener(this);
        binding.rlDevicePrice.setOnClickListener(this);
        binding.rgView.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(RadioGroup radioGroup, int i) {
                if (i == binding.radioTwo.getId()) {
                    if (binding.radioTwo.isChecked()) {
                        binding.llRate.setVisibility(View.GONE);
                    }
                }
                if (i == binding.radioOne.getId()) {
                    if (binding.radioOne.isChecked()) {
                        binding.llRate.setVisibility(View.VISIBLE);
                    }
                }
            }
        });
    }

    @Override
    protected void init() {
        inquiryCenterEntity = (InquiryCenterEntity) getIntent().getSerializableExtra("inquiryCenterEntity");
        pickPackersEntity = (PickPackersEntity) getIntent().getSerializableExtra("pickPackersEntity");
        pickPackersEntity2 = (PickDeviceEntity2) getIntent().getSerializableExtra("pickPackersEntity2");
        pickMaterialClassEntity = (PickMaterialClassEntity) getIntent().getSerializableExtra("pickMaterialClassEntity");
        pickLabourEntity = (PickLabourEntity) getIntent().getSerializableExtra("pickLabourEntity");
        bidEntity = (BidEntity) getIntent().getSerializableExtra("object");
        id = getIntent().getIntExtra("id", 0);
        setData();
    }

    public void setData() {
        if (pickPackersEntity != null) {
            /***
             * @SerializedName("type")
             *     private String name;
             *     @SerializedName("num")
             *     private String num;
             *     @SerializedName("depict")
             *     private String mark;
             *     @SerializedName("projName")
             *     private String projectInfo;
             *     @SerializedName("unit")
             *     private String unit;
             *     @SerializedName("projNo")
             *     private String projNo;
             */
            inquiryCenterEntity = new InquiryCenterEntity();
            inquiryCenterEntity.setNo(pickPackersEntity.getNo());
            inquiryCenterEntity.setProjectName(pickPackersEntity.getProjectInfo());
            inquiryCenterEntity.setName(pickPackersEntity.getName());
            inquiryCenterEntity.setUnit(pickPackersEntity.getUnit());
            inquiryCenterEntity.setNum(pickPackersEntity.getNum());
        }
        if (pickPackersEntity2 != null) {
            /***
             * @SerializedName("name")
             *     private String name;
             *     @SerializedName("type")
             *     private String type;
             *     @SerializedName("num")
             *     private String num;
             *     @SerializedName("mark")
             *     private String mark;
             *     @SerializedName("projName")
             *     private String projectInfo;
             *     @SerializedName("unit")
             *     private String unit;
             *     @SerializedName("projNo")
             *     private String projNo;
             *     @SerializedName("spec")
             *     private String spec;
             */
            id = R.layout.item_home_pick_device;
            inquiryCenterEntity = new InquiryCenterEntity();
            inquiryCenterEntity.setNo(pickPackersEntity2.getNo());
            inquiryCenterEntity.setProjectName(pickPackersEntity2.getProjectInfo());
            inquiryCenterEntity.setName(pickPackersEntity2.getName());
            inquiryCenterEntity.setUnit(pickPackersEntity2.getUnit());
            inquiryCenterEntity.setNum(pickPackersEntity2.getNum());
            /*binding.tvLable1.setText("分项工程名称：");
            binding.tvLable2.setText("计量单位：");
            binding.tvLable3.setText("工程量：");
            binding.tvLable4.setText("所属工程：");
            binding.tvProName.setText(inquiryCenterEntity.getName());
            binding.tvMaterialName.setText(inquiryCenterEntity.getUnit());
            binding.tvType.setText(inquiryCenterEntity.getNum());
            binding.tvNumber.setText(inquiryCenterEntity.getProjectName());*/
        }
        if (pickMaterialClassEntity != null) {
            /***
             * @SerializedName("name")
             *     private String name;
             *     @SerializedName("type")
             *     private String type;
             *     @SerializedName("num")
             *     private String num;
             *     @SerializedName("mark")
             *     private String mark;
             *     @SerializedName("projName")
             *     private String projectInfo;
             *     @SerializedName("unit")
             *     private String unit;
             *     @SerializedName("projNo")
             *     private String projNo;
             *     @SerializedName("spec")
             *     private String spec;
             */
            id = R.layout.item_home_pick_type;
            inquiryCenterEntity = new InquiryCenterEntity();
            inquiryCenterEntity.setNo(pickMaterialClassEntity.getNo());
            inquiryCenterEntity.setProjectName(pickMaterialClassEntity.getProjName());
            inquiryCenterEntity.setName(pickMaterialClassEntity.getName());
            inquiryCenterEntity.setSpec(pickMaterialClassEntity.getSpec());
            inquiryCenterEntity.setNum(pickMaterialClassEntity.getNum());
            /*binding.tvLable1.setText("分项工程名称：");
            binding.tvLable2.setText("计量单位：");
            binding.tvLable3.setText("工程量：");
            binding.tvLable4.setText("所属工程：");
            binding.tvProName.setText(inquiryCenterEntity.getName());
            binding.tvMaterialName.setText(inquiryCenterEntity.getUnit());
            binding.tvType.setText(inquiryCenterEntity.getNum());
            binding.tvNumber.setText(inquiryCenterEntity.getProjectName());*/
        }
        if (pickLabourEntity != null) {
            /***
             * @SerializedName("name")
             *     private String name;
             *     @SerializedName("type")
             *     private String type;
             *     @SerializedName("num")
             *     private String num;
             *     @SerializedName("mark")
             *     private String mark;
             *     @SerializedName("projName")
             *     private String projectInfo;
             *     @SerializedName("unit")
             *     private String unit;
             *     @SerializedName("projNo")
             *     private String projNo;
             *     @SerializedName("spec")
             *     private String spec;
             */
            id = R.layout.item_home_pick_labour;
            inquiryCenterEntity = new InquiryCenterEntity();
            inquiryCenterEntity.setNo(pickLabourEntity.getNo());
            inquiryCenterEntity.setProjectName(pickLabourEntity.getProjectInfo());
            inquiryCenterEntity.setName(pickLabourEntity.getName());
            inquiryCenterEntity.setUnit(pickLabourEntity.getUnit());
            inquiryCenterEntity.setNum(pickLabourEntity.getNum());
            /*binding.tvLable1.setText("分项工程名称：");
            binding.tvLable2.setText("计量单位：");
            binding.tvLable3.setText("数量：");
            binding.tvLable4.setText("所属工程：");
            binding.tvProName.setText(inquiryCenterEntity.getName());
            binding.tvMaterialName.setText(inquiryCenterEntity.getUnit());
            binding.tvType.setText(inquiryCenterEntity.getNum());
            binding.tvNumber.setText(inquiryCenterEntity.getProjectName());*/
        }

        if (bidEntity != null) {
            inquiryCenterEntity = new InquiryCenterEntity();
            if (id == R.layout.item_bid_material) {
                id = R.layout.item_home_pick_type;
                inquiryCenterEntity.setNo(bidEntity.getMid());
                inquiryCenterEntity.setProjectName(bidEntity.getProjectName());
                inquiryCenterEntity.setName(bidEntity.getName());
                inquiryCenterEntity.setSpec(bidEntity.getSpec());
                inquiryCenterEntity.setNum(bidEntity.getNum());
            } else if (id == R.layout.item_bid_machine) {
                id = R.layout.item_home_pick_device;
                inquiryCenterEntity.setNo(bidEntity.getMid());
                inquiryCenterEntity.setProjectName(bidEntity.getProjectName());
                inquiryCenterEntity.setName(bidEntity.getName());
                inquiryCenterEntity.setUnit(bidEntity.getUnit());
                inquiryCenterEntity.setNum(bidEntity.getNum());
            } else if (id == R.layout.item_bid_gc) {
                id = R.layout.item_pick_packers;
                inquiryCenterEntity.setNo(bidEntity.getMid());
                inquiryCenterEntity.setProjectName(bidEntity.getProjectName());
                inquiryCenterEntity.setName(bidEntity.getName());
                inquiryCenterEntity.setUnit(bidEntity.getUnit());
                inquiryCenterEntity.setNum(bidEntity.getNum());
            } else if (id == R.layout.item_bid_labor) {
                id = R.layout.item_home_pick_labour;
                inquiryCenterEntity.setNo(bidEntity.getMid());
                inquiryCenterEntity.setProjectName(bidEntity.getProjectName());
                inquiryCenterEntity.setName(bidEntity.getName());
                inquiryCenterEntity.setUnit(bidEntity.getUnit());
                inquiryCenterEntity.setNum(bidEntity.getNum());
            }
        }

        if (id == R.layout.item_home_pick_type) {
            binding.llFare.setVisibility(View.GONE);
            binding.llNumber.setVisibility(View.GONE);
            binding.llDevicePrice.setVisibility(View.GONE);
            binding.tvProName.setText(inquiryCenterEntity.getProjectName());
            binding.tvMaterialName.setText(inquiryCenterEntity.getName());
            binding.tvType.setText(inquiryCenterEntity.getSpec());
            binding.tvNumber.setText(inquiryCenterEntity.getNum());
        } else if (id == R.layout.item_home_pick_labour) {
            binding.tvLableName.setText("分包价");
            binding.llBrand.setVisibility(View.GONE);
            binding.llFare.setVisibility(View.GONE);
            binding.llNumber.setVisibility(View.GONE);
            binding.llDevicePrice.setVisibility(View.GONE);
            binding.tvLable1.setText("分项工程名称：");
            binding.tvLable2.setText("计量单位：");
            binding.tvLable3.setText("数量：");
            binding.tvLable4.setText("所属工程：");
            binding.tvProName.setText(inquiryCenterEntity.getName());
            binding.tvMaterialName.setText(inquiryCenterEntity.getUnit());
            binding.tvType.setText(inquiryCenterEntity.getNum());
            binding.tvNumber.setText(inquiryCenterEntity.getProjectName());
        } else if (id == R.layout.item_home_pick_device) {
            binding.llComePrice.setVisibility(View.GONE);
            binding.llBrand.setVisibility(View.GONE);
            binding.llDevicePrice.setVisibility(View.VISIBLE);
            binding.tvLable1.setText("设备机械名称：");
            binding.tvLable2.setText("计量单位：");
            binding.tvLable3.setText("数量：");
            binding.tvLable4.setText("所属项目：");
            binding.tvProName.setText(inquiryCenterEntity.getName());
            binding.tvMaterialName.setText(inquiryCenterEntity.getUnit());
            binding.tvType.setText(inquiryCenterEntity.getNum());
            binding.tvNumber.setText(inquiryCenterEntity.getProjectName());
        } else if (id == R.layout.item_pick_packers) {
            binding.tvLableName.setText("分包价");
            binding.llBrand.setVisibility(View.GONE);
            binding.llFare.setVisibility(View.GONE);
            binding.llNumber.setVisibility(View.GONE);
            binding.llDevicePrice.setVisibility(View.GONE);
            binding.tvLable1.setText("分项工程名称：");
            binding.tvLable2.setText("计量单位：");
            binding.tvLable3.setText("工程量：");
            binding.tvLable4.setText("所属工程：");
            binding.tvProName.setText(inquiryCenterEntity.getName());
            binding.tvMaterialName.setText(inquiryCenterEntity.getUnit());
            binding.tvType.setText(inquiryCenterEntity.getNum());
            binding.tvNumber.setText(inquiryCenterEntity.getProjectName());
        }
    }

    @SuppressWarnings("unchecked")
    private void showRatePop() {
        OptionsPickerView businessOption = new OptionsPickerBuilder(QuoteImmediatelyActivity.this, (options1, options2, options3, v) -> {
            String content = rateEntityList.get(options1).getRate();
            binding.etRate.setText(content);
            rateId = rateEntityList.get(options1).getId();
            ratePosition = options1;
        }).build();
        businessOption.setPicker(rateEntityList);
        businessOption.setSelectOptions(ratePosition);
        businessOption.show();
    }

    @SuppressWarnings("unchecked")
    private void showUnitPop() {
        OptionsPickerView businessOption = new OptionsPickerBuilder(QuoteImmediatelyActivity.this, (options1, options2, options3, v) -> {
            String content = machinePriceUnitEntities.get(options1).getName();
            binding.tvUnit.setText(content);
            no = machinePriceUnitEntities.get(options1).getNo();
            unitPosition = options1;
        }).build();
        businessOption.setPicker(machinePriceUnitEntities);
        businessOption.setSelectOptions(unitPosition);
        businessOption.show();
    }

    public void getRateData(List<RateEntity> rateEntityList) {
        this.rateEntityList = rateEntityList;
        showRatePop();
    }

    public void getUnitDate(List<MachinePriceUnitEntity> machinePriceUnitEntities) {
        this.machinePriceUnitEntities = machinePriceUnitEntities;
        showUnitPop();
    }

    private void checkData() {
        if (TextUtils.isEmpty(binding.etPrice.getText()) && id == R.layout.item_home_pick_type) {
            MToast.showToast(QuoteImmediatelyActivity.this, "请填写送到价");
            return;
        }
        if (TextUtils.isEmpty(binding.etPrice.getText()) && id == R.layout.item_home_pick_labour) {
            MToast.showToast(QuoteImmediatelyActivity.this, "请填写分包价");
            return;
        }
        if (TextUtils.isEmpty(binding.etPrice.getText()) && id == R.layout.item_pick_packers) {
            MToast.showToast(QuoteImmediatelyActivity.this, "请填写分包价");
            return;
        }
        if (TextUtils.isEmpty(binding.etDevicePrice.getText()) && id == R.layout.item_home_pick_device) {
            MToast.showToast(QuoteImmediatelyActivity.this, "请填写租凭价格");
            return;
        }
        if (binding.tvUnit.getText().equals("请选择") && id == R.layout.item_home_pick_device) {
            MToast.showToast(QuoteImmediatelyActivity.this, "请选择租凭单位");
            return;
        }
        if (TextUtils.isEmpty(binding.etNumber.getText()) && id == R.layout.item_home_pick_device) {
            MToast.showToast(QuoteImmediatelyActivity.this, "请填写出租数量");
            return;
        }
        if (TextUtils.isEmpty(binding.etFare.getText()) && id == R.layout.item_home_pick_device) {
            MToast.showToast(QuoteImmediatelyActivity.this, "请填写运费");
            return;
        } else if (TextUtils.isEmpty(binding.etBrand.getText()) && id == R.layout.item_home_pick_type) {
            MToast.showToast(QuoteImmediatelyActivity.this, "请填写品牌");
            return;
        } else if (TextUtils.isEmpty(binding.etRate.getText()) && !binding.radioTwo.isChecked()) {
            MToast.showToast(QuoteImmediatelyActivity.this, "请选择税率");
            return;
        }
        if (id == R.layout.item_home_pick_type) {
            offerMaterialEntity = new OfferMaterialEntity();
            offerMaterialEntity.setNo(inquiryCenterEntity.getNo());
            offerMaterialEntity.setBrand(binding.etBrand.getText().toString());
            offerMaterialEntity.setPrice(binding.etPrice.getText().toString());
            if (binding.radioOne.isChecked()) {
                offerMaterialEntity.setType("1");
            } else if (binding.radioTwo.isChecked()) {
                offerMaterialEntity.setType("3");
            }
            offerMaterialEntity.setRate(rateId);
            model.commitOfferMaterial(offerMaterialEntity);
        } else if (id == R.layout.item_home_pick_labour) {
            offerLabourEntity = new OfferLabourEntity();
            offerLabourEntity.setNo(inquiryCenterEntity.getNo());
            offerLabourEntity.setPrice(binding.etPrice.getText().toString());
            if (binding.radioOne.isChecked()) {
                offerLabourEntity.setType("1");
            } else if (binding.radioTwo.isChecked()) {
                offerLabourEntity.setType("3");
            }
            offerLabourEntity.setRate(rateId);
            model.commitOfferLabour(offerLabourEntity);
        } else if (id == R.layout.item_home_pick_device) {
            offerDeviceEntity = new OfferDeviceEntity();
            offerDeviceEntity.setNo(inquiryCenterEntity.getNo());
            offerDeviceEntity.setNum(binding.etNumber.getText().toString());
            offerDeviceEntity.setPrice(binding.etDevicePrice.getText().toString());
            if (binding.radioOne.isChecked()) {
                offerDeviceEntity.setType("1");
            } else if (binding.radioTwo.isChecked()) {
                offerDeviceEntity.setType("3");
            }
            offerDeviceEntity.setRate(rateId);
            offerDeviceEntity.setCarriage(binding.etFare.getText().toString());
            offerDeviceEntity.setUnit(no);
            model.commitOfferMachine(offerDeviceEntity);
        } else if (id == R.layout.item_pick_packers) {
            offerLabourEntity = new OfferLabourEntity();
            offerLabourEntity.setNo(inquiryCenterEntity.getNo());
            offerLabourEntity.setPrice(binding.etPrice.getText().toString());
            if (binding.radioOne.isChecked()) {
                offerLabourEntity.setType("1");
            } else if (binding.radioTwo.isChecked()) {
                offerLabourEntity.setType("3");
            }
            offerLabourEntity.setRate(rateId);
            model.engineerOffer(offerLabourEntity);
        }
    }

    public void showSuccess() {
        SuccessEntity successEntity = new SuccessEntity();
        successEntity.setTitle("报价成功");
        successEntity.setContent("您的报价信息已提交成功");
        successEntity.setButtonText("确定");
        successEntity.setType(PICK_OFFER);
        successEntity.setId(id);
        CommitSuccessActivity.start(this, successEntity);
    }

    /**
     * 隐藏软键盘
     */
    private void setSoftWareHide() {
        InputMethodManager imm = (InputMethodManager) this.getSystemService(Context.INPUT_METHOD_SERVICE);
        if (imm != null) {
            imm.hideSoftInputFromWindow(this.getWindow().getDecorView().getWindowToken(), 0);
        }
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.back_view:
                finish();
                break;
            case R.id.rl_tax_rate:
                setSoftWareHide();
                if (rateEntityList != null) {
                    showRatePop();
                } else {
                    model.getRateList();
                }
                break;
            case R.id.tv_commit:
                checkData();
                break;
            case R.id.rl_device_price:
                setSoftWareHide();
                if (machinePriceUnitEntities != null) {
                    showUnitPop();
                } else {
                    model.machinePriceUnit();
                }
                break;
        }
    }
}
